package com.ruoyi.background.service.impl;

import com.ruoyi.background.domain.AppGradeRecord;
import com.ruoyi.background.mapper.AppGradeRecordMapper;
import com.ruoyi.background.service.IAppGradeRecordService;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 积分记录Service业务层处理
 *
 * @author susu
 * @date 2024-08-18
 */
@Service
public class AppGradeRecordServiceImpl implements IAppGradeRecordService {
    @Autowired
    private AppGradeRecordMapper appGradeRecordMapper;

    /**
     * 查询积分记录
     *
     * @param id 积分记录主键
     * @return 积分记录
     */
    @Override
    public AppGradeRecord selectAppGradeRecordById(Long id) {
        return appGradeRecordMapper.selectAppGradeRecordById(id);
    }

    /**
     * 查询积分记录列表
     *
     * @param appGradeRecord 积分记录
     * @return 积分记录
     */
    @Override
    public List<AppGradeRecord> selectAppGradeRecordList(AppGradeRecord appGradeRecord) {
        return appGradeRecordMapper.selectAppGradeRecordList(appGradeRecord);
    }

    /**
     * 新增积分记录
     *
     * @param appGradeRecord 积分记录
     * @return 结果
     */
    @Override
    public int insertAppGradeRecord(AppGradeRecord appGradeRecord) {
        appGradeRecord.setCreateTime(DateUtils.getNowDate());
        return appGradeRecordMapper.insertAppGradeRecord(appGradeRecord);
    }

    /**
     * 修改积分记录
     *
     * @param appGradeRecord 积分记录
     * @return 结果
     */
    @Override
    public int updateAppGradeRecord(AppGradeRecord appGradeRecord) {
        return appGradeRecordMapper.updateAppGradeRecord(appGradeRecord);
    }

    /**
     * 批量删除积分记录
     *
     * @param ids 需要删除的积分记录主键
     * @return 结果
     */
    @Override
    public int deleteAppGradeRecordByIds(Long[] ids) {
        return appGradeRecordMapper.deleteAppGradeRecordByIds(ids);
    }

    /**
     * 删除积分记录信息
     *
     * @param id 积分记录主键
     * @return 结果
     */
    @Override
    public int deleteAppGradeRecordById(Long id) {
        return appGradeRecordMapper.deleteAppGradeRecordById(id);
    }


    /**
     * 获取用户累计获取的积分
     *
     * @return int
     */
    @Override
    public Integer getUserCountInGrade() {
        Integer grade = appGradeRecordMapper.getUserCountInGrade(SecurityUtils.getUserId());
        return null == grade ? 0 : grade;
    }

    /**
     * 获取用户累计获取的积分
     *
     * @return int
     */
    @Override
    public Integer getUserCountInGrade(Long userId) {
        Integer grade = appGradeRecordMapper.getUserCountInGrade(userId);
        return null == grade ? 0 : grade;
    }
}
